package com.huike.web.controller.report;


import com.huike.business.domain.vo.BusinessChangeStatisticsVO;
import com.huike.business.service.ITbBusinessService;
import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.clues.domain.vo.SalesStatisticVO;
import com.huike.clues.service.ITbClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;

    @Autowired
    private ITbBusinessService tbBusinessService;

    @Autowired
    private ITbClueService tbClueService;


    /**
     * 首页--基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    @GetMapping
    public AjaxResult getIndex(@RequestParam("beginCreateTime") String beginCreateTime,
                               @RequestParam("endCreateTime") String endCreateTime) {
        IndexStatisticsVo request = new IndexStatisticsVo();
        request.setBeginCreateTime(beginCreateTime);
        request.setEndCreateTime(endCreateTime);
        Map result = reportService.getIndex(request);
        return AjaxResult.success(result);
    }

    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                               @RequestParam("endCreateTime") String endCreateTime) {
        List<BusinessChangeStatisticsVO> businessChangeStatisticsVOList = tbBusinessService.businessChangeStatistics(beginCreateTime, endCreateTime);
        return AjaxResult.success(businessChangeStatisticsVOList);
    }

    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(@RequestParam("beginCreateTime") String beginCreateTime,
                                     @RequestParam("endCreateTime") String endCreateTime) {
        List<SalesStatisticVO> salesStatisticVOList = tbClueService.salesStatistic(beginCreateTime, endCreateTime);
        return AjaxResult.success(salesStatisticVOList);
    }
}
